package com.meng.menggaga.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.meng.menggaga.R;
import com.meng.menggaga.util.CommonParameter;


/**
 * 登录页面
 * 
 * 用户名，密码登录
 * 
 * 第三方登录（新浪微博，QQ，微信）
 * 
 * @author simba
 * 
 */
public class LoginActivity extends BaseActivity implements OnClickListener {
    private EditText vUserName;
    private EditText vPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setTitle(R.string.login);
    }

    @Override
    protected int layoutResId() {
        return R.layout.activity_login;
    }

    @Override
    protected void initViews() {
        super.initViews();
        vUserName = (EditText) findViewById(R.id.username);
        vPassword = (EditText) findViewById(R.id.password);
    }

    @Override
    protected void initEvents() {
        super.initEvents();
        Button login = (Button) findViewById(R.id.login);
        login.setOnClickListener(this);
        login.findViewById(R.id.login).setBackgroundColor(
                getResources().getColor(CommonParameter.sStyleBgColor));
        login.setTextColor(getResources().getColor(CommonParameter.sStyleTextViewColor));
    }

    @Override
    public void onClick(View arg0) {
        int id = arg0.getId();
        if (id == R.id.login) {
            if (isInputed()) {

            }
        }
    }

    private boolean isInputed() {
        if (TextUtils.isEmpty(vUserName.getText().toString())) {
            YoYo.with(Techniques.Tada).duration(700).playOn(findViewById(R.id.username));
            return false;
        }
        if (TextUtils.isEmpty(vPassword.getText().toString())) {
            YoYo.with(Techniques.Tada).duration(700).playOn(findViewById(R.id.password));
            return false;
        }
        return true;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Only show items in the action bar relevant to this screen
        // if the drawer is not showing. Otherwise, let the drawer
        // decide what to show in the action bar.
        getMenuInflater().inflate(R.menu.login, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            finish();
            return true;
        } else if (id == R.id.register) {
            startActivity(new Intent(this, RegisterActvity.class));
        }
        return super.onOptionsItemSelected(item);
    }
}
